package carTest;

import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @description:
 * @author: 张德长 dechang.zhang@ucarinc.com
 * @date: 10:19:02 2018/11/1
 * @version:2.0
 */
public class Doc {

    public int interfaceType = 1;
    public String responseTemplate = "object";
    public String interfaceTreeId;
    //public String[] invokeInterfaces=[];
    public String userId;
    public String name;
    public String requestUrl;
    public String requestType;
    public String description;//description +  serviceid +method
    public List<RequestPara> requestParam;
    public List<ResponPara> responseParam;

    public void rpc2httpParam(Set excludeRequest) {
        List<RequestPara> requestParamTmp = new ArrayList<>();
        for (int i = 0; i < requestParam.size(); i++) {
            RequestPara requestPara = requestParam.get(i);
            requestPara.id = i + 1;
            requestPara.rpc2HttpPara();
           // System.out.println(requestPara.getIdentifier()+"是否排除"+excludeRequest.contains(requestPara.getIdentifier()));
            if (excludeRequest.contains(requestPara.getIdentifier())) {
            } else {
                requestParamTmp.add(requestPara);
            }
        }
        requestParam = requestParamTmp;
        String initResponse = "[{\"id\":\"1\",\"parentId\":\"0\",\"level\":\"1\",\"identifier\":\"status\",\"name\":\"状态\",\"dataType\":\"Integer\",\"type\":2},{\"id\":\"2\",\"parentId\":\"0\",\"level\":\"1\",\"identifier\":\"content\",\"name\":\"内容\",\"dataType\":\"Object\",\"type\":2},{\"id\":\"3\",\"parentId\":\"0\",\"level\":\"1\",\"identifier\":\"msg\",\"name\":\"信息\",\"dataType\":\"String\",\"type\":2},{\"id\":\"4\",\"parentId\":\"0\",\"level\":\"1\",\"identifier\":\"version\",\"name\":\"响应的API服务器版本信息\",\"dataType\":\"String\",\"type\":2},{\"id\":\"5\",\"parentId\":\"0\",\"level\":\"1\",\"identifier\":\"uid\",\"name\":\"会话id\",\"dataType\":\"String\",\"type\":2},{\"id\":\"6\",\"parentId\":\"0\",\"level\":\"1\",\"identifier\":\"handler\",\"name\":\"标志该条结果应该由谁来进行处理\",\"dataType\":\"String\",\"type\":2},{\"id\":\"7\",\"parentId\":\"0\",\"level\":\"1\",\"identifier\":\"busiCode\",\"name\":\"增值代码\",\"dataType\":\"String\",\"type\":2},{\"id\":\"8\",\"parentId\":\"0\",\"level\":\"1\",\"identifier\":\"code\",\"name\":\"状态的唯一标识符\",\"dataType\":\"Integer\",\"type\":2}]";
        List<ResponPara> responInitParam = JSONObject.parseObject(initResponse, List.class);
        int index = 0;
        for (int i = 0; i < responseParam.size(); i++) {
            ResponPara responPara = responseParam.get(i);

            if (Integer.parseInt(responPara.level) > 1) {
                responPara.rpc2HttpPara();
                //responPara.id = index + 9 + "";//修改id 会使子id有问题。
                // index++;
                if (Integer.parseInt(responPara.level) == 2) {
                    responPara.parentId = "2";//第二级的父ID关联到content中
                }
                responInitParam.add(responPara);
            }
        }
        responseParam = responInitParam;
    }
}
